package vno.fux.character
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import vno.fux.BaseDisplayObject;
	import vno.fux.BasePoint;
	import vno.fux.events.NpcEvent;

	public class NpcLayer extends BaseDisplayObject
	{
		private var _Npcs:Dictionary;
		private var _layerView:Sprite;
		private var _settings:XMLList;
		public function NpcLayer(layerSetting:XMLList)
		{
			this.mouseEnabled = false;
			
			_Npcs = new Dictionary;
			_layerView = new Sprite;
			_layerView.mouseEnabled = false;
			_settings = layerSetting;
			for each(var setting:XML in layerSetting.npc)
			{
				var npc:Npc = new Npc(
					setting.@id, 
					setting.@resId, 
					new BasePoint(setting.@x,setting.@y));
				_Npcs[uint(setting.@id)] = npc;
				listenIni(npc);
				//trace(_Npcs[uint(Npc.@id)]);
				//trace(uint(Npc.@id));
				_layerView.addChild(npc.view);
			}
			
			
			this.content = _layerView;
		}
		
		private function listenIni(npc_:Npc):void
		{
			npc_.controller.addEventListener(NpcEvent.CLICK, eventHandler);
		}
		
		private function eventHandler(event:Event):void
		{
			dispatchEvent(event);
		}
		
		public function mapMove(pos:BasePoint):void
		{
			this.setRegPoint(pos);
		}
	}
}